home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MATH.SWG / 0002_CIRCLE3P.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  4KB  |  141 lines

  1. Program ThreePoints_TwoPoints;
  2. {
  3.  
  4.    I Really appreciate ya helping me With this 3 points on a
  5. circle problem. The only thing is that I still can't get it
  6. to work. I've tried the Program you gave me and it spits out
  7. the wrong answers. I don't know if there are parentheses in the
  8. wrong place or what. Maybe you can find the error.
  9.  
  10.    You'll see that I've inserted True coordinates For this test.
  11.  
  12. Thank you once again...and please, when you get any more information
  13. on this problem...call me collect person to person or leave it on my
  14. BBS. I get the turbo pascal echo from a California BBS and that sure
  15. is long distance. Getting a good pascal Procedure For this is
  16. important to me because I am using it in a soon to be released math
  17. Program called Mr. Machinist! I've been racking my brain about this
  18. for 2 weeks now and I've even been dream'in about it!
  19.  
  20. Your help is appreciated!!!
  21.  
  22.  +
  23. +AL+
  24.  
  25. (716) 434-7823 Voice
  26. (716) 434-1448 BBS ... if none of these, then leave Program on TP echo.
  27.  
  28. }
  29.  
  30. Uses
  31.   Crt;
  32. Const
  33.   x1 =  4.0642982;
  34.   y1 =  0.9080732;
  35.   x2 =  1.6679862;
  36.   y2 =  2.8485684;
  37.   x3 =  4.0996421;
  38.   y3 =  0.4589868;
  39.  
  40. Var
  41.   Selection : Integer;
  42. Procedure ThreePoints;
  43. Var
  44.   Slope1,
  45.   Slope2,
  46.   Mid1x,
  47.   Mid1y,
  48.   Mid2x,
  49.   Mid2y,
  50.   Cx,
  51.   Cy,
  52.   Radius : Real;
  53. begin
  54.   ClrScr;
  55.   Writeln('3 points on a circle');
  56.   Writeln('====================');
  57.   Writeln;
  58.   Writeln('X1 ->  4.0642982');
  59.   Writeln('Y1 ->  0.9080732');
  60.   Writeln;
  61.   Writeln('X2 ->  1.6679862');
  62.   Writeln('Y2 ->  2.8485684');
  63.   Writeln('X3 ->  4.0996421');
  64.   Writeln('Y3 ->  0.4589868');
  65.   Writeln;
  66.   Slope1 := (y2 - y1) / (x2 - x1);
  67.   Slope2 := (y3 - y2) / (x3 - x2);
  68.   Mid1x  := (x1 + x2) / 2;
  69.   Mid1y  := (y1 + y2) / 2;
  70.   Mid2x  := (x2 + x3) / 2;
  71.   Mid2y  := (y2 + y3) / 2;
  72.   Slope1 := -1 * (1 / Slope1);
  73.   Slope2 := -1 * (1 / Slope2);
  74.   Cx     := (Slope2 * x2 - y2 - Slope1 * x1 + y1) / (Slope1 - Slope2);
  75.   Cy     := Slope1 * (Cx + x1) - y1;
  76.  
  77.   {
  78.   I believe you missed out on using Cx and Cy in next line,
  79.   Radius := sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)));
  80.   I think it should be . . .
  81.   }
  82.  
  83.   Radius := Sqrt(Sqr((x1 - Cx) + (y1 - Cy)));
  84.   Writeln;
  85.   Writeln('X center line (Program answer) is ', Cx : 4 : 4);
  86.   Writeln('Y center line (Program answer) is ', Cy : 4 : 4);
  87.   Writeln('The radius    (Program answer) is ', Radius : 4 : 4);
  88.   Writeln;
  89.   Writeln('True X center = 1.7500');
  90.   Writeln('True Y center = 0.5000');
  91.   Writeln('True Radius   = 2.3500');
  92.   Writeln('Strike any key to continue . . .');
  93.   ReadKey;
  94. end;
  95.  
  96. Procedure Distance2Points;
  97. Var
  98.   x1, y1,
  99.   x2, y2,
  100.   Distance : Real;
  101. begin
  102.   ClrScr;
  103.   Writeln('Distance between 2 points');
  104.   Writeln('=========================');
  105.   Writeln;
  106.   Write('X1 -> ');
  107.   Readln(x1);
  108.   Write('Y1 -> ');
  109.   Readln(y1);
  110.   Writeln;
  111.   Write('X2 -> ');
  112.   Readln(x2);
  113.   Write('Y2 -> ');
  114.   Readln(y2);
  115.   Writeln;
  116.   Writeln;
  117.   Distance := Sqrt((Sqr(x2 - x1)) + (Sqr(y2 - y1)));
  118.   Writeln('Distance between point 1 and point 2 = ', Distance : 4 : 4);
  119.   Writeln;
  120.   Writeln('Strike any key to continue . . .');
  121.  
  122.   ReadKey;
  123. end;
  124.  
  125. begin
  126.   ClrScr;
  127.   Writeln;
  128.   Writeln;
  129.   Writeln('1) Distance between 2 points');
  130.   Writeln('2) 3 points on a circle test Program');
  131.   Writeln('0) Quit');
  132.   Writeln;
  133.   Write('Choose a menu number: ');
  134.   Readln(Selection);
  135.     Case Selection of
  136.       1 : Distance2Points;
  137.       2 : ThreePoints;
  138.     end;
  139.   ClrScr;
  140. end.
  141.